<?php

namespace app\admin\model\xmwms;

use think\Model;

/**
 * Relocation
 */
class Relocation extends Model
{
    // 表名
    protected $name = 'wms_relocation';

    /**
     * @var string 自动写入时间戳字段
     */
    protected $autoWriteTimestamp = true;

    public $append = [
        'audit_status_text'
    ];

    // 字段类型转换
    protected $type = [
        'updatetime' => 'timestamp:Y-m-d H:i:s',
        'deletetime' => 'timestamp:Y-m-d H:i:s',
    ];

    public function getAuditStatusTextAttr($value, $row): string
    {
        if ($row['audit_status'] === '' || $row['audit_status'] === null) return '';
        $row['audit_status'] == 1 ? $value = '已审核' : $value = '未审核';
        return $value;
    }

    public function admin()
    {
        return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
    }

    public function relocationDetail()
    {
        return $this->hasMany(RelocationDetail::class, 'relocation_no', 'relocation_no');
    }

}